/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.hnilica.cisteniulic.bean;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import net.hnilica.cisteniulic.dao.UliceDAO;
import net.hnilica.cisteniulic.dto.Ulice;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 *
 * @author swosh
 */
public class WatchedUlice {

    public String getWatchedUlice() {
        UliceDAO uliceDAO = new UliceDAO();
        Subject subject = SecurityUtils.getSubject();
        //principal is sam as an email in database
        String principal = (String) subject.getPrincipal();
        Collection<Ulice> collUlice = uliceDAO.getWatchedUlice(principal);
        StringBuffer sb = new StringBuffer();
        sb.append("<td>");
        sb.append("<ul class='sprava_seznam'>");
        int anchor = 0;

        for (Iterator<Ulice> it = collUlice.iterator(); it.hasNext();) {
            Ulice ulice = it.next();
            sb.append("<li class='sprava_seznam'><form action='deleteUlice' name='delete_ulice' method='post'>");
            sb.append("<a name=").append("'anchor").append(anchor).append("'></a>");
            sb.append("<input name='anchor' type='hidden' value=\"").append(anchor++).append("\"/>");
            sb.append("<input name='delete_ulice' type='hidden' value=\"");
            sb.append(ulice.getNazUlice());
            sb.append("\"/>");
            sb.append("<input name='ok' class=' cancel_img_white_bg' type='submit' value=\"");
            sb.append("&#160;&#160;&#160;&#160;" + ulice.getNazUlice().replaceFirst(" ", "&#160;"));
            sb.append("\"/></form>");
            sb.append("</li>");
        }

        sb.append("</ul></td>");
        return sb.toString();

    }

}
